package fr.umlv.m2.jee.spij.persistence.actor.dao;

import fr.umlv.m2.jee.spij.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.spij.persistence.actor.ITeacherUnitDAO;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherUnit;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 */
@Repository("hibernateTeacherUnitDAO")
public class HibernateTeacherUnitDAO extends
        AbstractHibernateDAO<Long, TeacherUnit> implements ITeacherUnitDAO {

    /**
     * Finds a teacher from it login an returns all this Unit.
     *
     * @param teacherLogin the teacher login.
     *
     * @return a list of TeacherUnit.
     */
    public final List<TeacherUnit> findByTeacherLogin(
            final String teacherLogin) {
        Session session = getHibernateSession();
        Criteria criteria = session.createCriteria(TeacherUnit.class);
        criteria.add(Restrictions.eq("teacherLogin", teacherLogin));
        return criteria.list();
    }
}
